package com.teach;

/**
 * <pre>
 * -
 * Author : J.L.Zhou
 * E-Mail : 2233875735@qq.com
 * Tel : 151 1104 7708
 * Date : 2021-04-09 15:12
 * Version : 1.0
 * Copyright 2021 jlzhou.top Inc. All rights reserved.
 * Warning: this content is only for internal circulation of the company.
 *          It is forbidden to divulge it or use it for other commercial purposes.
 * </pre>
 **/
public class Demo11 {
  public static void main(String[] args) {
//    System.out.println(division(10, 1));
    try {
      System.out.println(division(10, 0));
    }catch (Exception e){
      System.out.println("调用除法运算方法失败:"+e.getMessage());
      System.out.println("更底层的原因:"+e.getCause().getMessage());
      e.printStackTrace();
    }
  }

  public static int division(int x,int y)throws Exception{
    try{
//      if(y==0){
////        throw new Exception();
//        throw new Exception("不能被0除!");
//      }
      System.out.println("x/y="+x/y);
      System.out.println("x/y计算结束");
      return x/y;
    }catch(ArithmeticException e){
      System.out.println("发生了数学异常，注意除数不能为0.");
//      throw e;
//      throw new Exception();
//      throw new Exception("不能被0除!");
      throw new Exception("不能被0除!",e);
//      return 0;
    }finally{
      System.out.println("finally代码块");
    }
  }
}
